﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Management/Site.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
   <script src="../js/jquery-1.7.1.min.js" type="text/javascript"></script>    
    <script src="../js/jquery.ui.js" type="text/javascript"></script>
    <script src="../js/repeater.js" type="text/javascript"></script>
    <script src="../js/pager.js" type="text/javascript"></script>  
    <link href="../styles/pager.css" rel="stylesheet" type="text/css" />
    <link href="../styles/style.css" rel="stylesheet" type="text/css" />        
    <script src="../js/blockUI.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="search_table">
        <tr>
            <td class="tdtitle" style="width:50px;">
                姓名
            </td>
            <td class="tdcontent">
                <input id="name" name="name" type="text" size="10" />
            </td>
            <td class="tdtitle" style="width:50px;">
                邮箱：
            </td>
            <td colspan="2">
                <input id="email" name="email" type="text" size="25" />
            </td>
             <td class="tdtitle" style="width:50px;">
                留言：
            </td>
            <td colspan="2">
                <input id="message" name="message" type="text" size="30" />
            </td>            
            <td class="tdtitle" style="width:50px;">
                状态
            </td>
            <td class="tdcontent">
                <select id="state" name="state">
                    <option value="">全部</option>
                    <option value="2">答复</option>
                    <option value="3">拒绝</option>
                </select>
            </td>
            <td>
                <input id="btn_search" value="搜索" type="button" />
            </td>
        </tr>
        <tr>
            <td colspan="11">
                <input id="btn_delete" type="button" value="批量删除" />
                <a href="Edit.aspx?code=-1">新增</a>
            </td>
        </tr>
    </table>
    <table id="list">
        <thead>
            <tr>
                <th>
                    <input type="checkbox" id="chkall" />全选
                </th>
                <th>
                    姓名
                </th>
                <th>
                    邮箱
                </th>
                <th>
                    留言
                </th>
                <th>
                    答复
                </th>
                <th>
                    编辑
                </th>
                <th>
                    排序
                </th>
                <th>
                    删除
                </th>
            </tr>
        </thead>
        <tbody>
            <!--<tr><td><input type="checkbox" class="chkitem" value='[Code]' /></td><td>[Name]</td><td>[Email]</td><td style="width:190px;Word-break: break-all;">[Message]</td><td style="width:190px;Word-break: break-all;">[Remark]</td><td><span class="edit" code="[Code]"><a href="Edit.aspx?code=[Code]">编辑</a></span></td><td><span class="up" code='[Code]'>向上</span>&nbsp;<span class="down" code='[Code]'>向下</span></td><td><span class="delete" code='[Code]'>删除</span></td></tr>-->
        </tbody>
        <tfoot>
            <tr>
                <td colspan="8">
                    <div id="pager" psize='15'>
                    </div>
                </td>
            </tr>
        </tfoot>
    </table>
    <script type="text/javascript">
        $(function () {
            var $list = $("#list>tbody:first");
            var BindData = function () {
                $list.template({ autoBind: false });
                $.blockUI({ message: "<h2>数据加载中.......</h2>", css: { width: "300px", height: "50px"} });
                $.ajax({ url: "../AjaxHandler/UserMessageList.ashx?t=" + new Date(),
                    data: {
                        pindex: 1,
                        psize: $("#pager").attr("psize"),
                        action: "List",
                        name:$("#name").val(),
                        email:$("#email").val(),
                        message: $("#message").val(),
                        state: $("#state").val()
                    },
                    type: "post",
                    success: function (data) {
                        pcount = data.Data.Pager.PageCount;
                        $("#pager").pager({ pagenumber: 1, pagecount: pcount, buttonClickCallback: PageClick });
                        $list.template("bindData", data.Data.Rows);
                        $.unblockUI();

                    }
                });

                $list.find("tr", function () {
                    $(this).addClass("altertr");
                });
            }
            BindData();
            //分页标签事件
            var PageClick = function (pageclickednumber) {

                $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pcount, buttonClickCallback: PageClick });
                $.ajax({ url: "../AjaxHandler/UserMessageList.ashx?t=" + new Date(),
                    data: {
                        pindex: pageclickednumber,
                        psize: $("#pager").attr("psize"),
                        action: "List"
                    },
                    type: "post",
                    success: function (data) {
                        $list.template("bindData", data.Data.Rows);
                    }
                });
            }
            //高亮选中行
            $list.delegate("tr", "mouseover", function () {
                $(this).addClass("altertr");
            });
            //取消高亮选中行
            $list.delegate("tr", "mouseout", function () {
                $(this).removeClass("altertr");
            });
            //排序开始
            $list.delegate("span.up", "click", function () {
                var code = $(this).attr("code");
                Order(true, code); //向上排序
            });

            $list.delegate("span.down", "click", function () {
                var code = $(this).attr("code");
                Order(false, code); //向下排序
            });

            //排序函数
            var Order = function (moveUp, id) {
                $.post("../AjaxHandler/UserMessageList.ashx?t=" + new Date(), { action: "Order", up: moveUp, code: id }, function (d) {
                    if (d == "1") {
                        BindData();
                    } else {
                        alert("排序失败！");
                    }
                })
            }

            //排序结束

            //单个删除开始
            $list.delegate("span.delete", "click", function () {
                if (confirm("确定要删除吗？")) {
                    var id = $(this).attr("code");
                    $.post("../AjaxHandler/UserMessageList.ashx?t=" + new Date(), { action: "Delete", code: id }, function (d) {
                        if (d == "1") {
                            alert("删除成功！");
                            BindData();
                        } else {
                            alert("删除失败！");
                        }
                    })
                }
            })
            //单个删除结束

            //批量删除开始
            $("#btn_delete").click(function () {

                var ids = $("#chkall").data("ids");
                if (typeof (ids) == "undefined") {
                    alert("请选择要删除的项！");
                    return;
                } else {
                    if (ids.length == 0) {
                        alert("请选择要删除的项！");
                        return;
                    }
                    if (confirm("确定要删除吗？")) {
                        $.post("../AjaxHandler/TourismInfoList.ashx?t=" + new Date(), { action: "DeleteAll", ids: ids, tablename: "UserMessage" }, function (d) {
                            if (d) {
                                alert("删除成功！");
                                BindData();
                                $("#chkall").data("ids", "");
                            } else {
                                alert("删除失败！");
                            }
                        });
                    }
                }
            })
            //批量删除结束

            //全选开始
            $("#chkall").click(function () {
                if ($(this).attr("checked")) {
                    $("input[type=checkbox]").attr("checked", $(this).attr("checked"));
                    var ids = new Array();
                    $("input.chkitem").each(function () {
                        ids += "'" + $(this).val() + "',";
                    })
                    $(this).data("ids", ids);
                } else {
                    $("input[type=checkbox]").removeAttr("checked");
                    $(this).data("ids", "");
                }
            });
            //全选结束
            //单选开始
            $list.delegate(".chkitem", "click", function () {
                if ($(this).attr("checked")) {
                    if ($("#chkall").data("ids") != null) {
                        $("#chkall").data("ids", $("#chkall").data("ids") + "'" + $(this).val() + "',");
                    } else {
                        $("#chkall").data("ids", "'" + $(this).val() + "',");
                    }
                } else {
                    $("#chkall").data("ids", $("#chkall").data("ids").replace("'" + $(this).val() + "',", ""));
                }
            });
            //单选结束

            //搜索按钮事件开始
            $("#btn_search").click(function () {
                BindData();
            });
            //搜索按钮事件结束
        })
    </script>
</asp:Content>
